package cn.vcjf.weapp.api.setting.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.setting.entity.FreightTemplate;
import cn.vcjf.weapp.api.setting.service.FreightTemplateService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/setting/freightTemplate")
public class FreightTemplateController {
     @Resource
     private FreightTemplateService  freightTemplateService;

     @RequestMapping("/addFreightTemplate")
     @ResponseBody
     public TableResult addFreightTemplate(FreightTemplate freightTemplate){
         freightTemplate.preInsert();
         boolean b = freightTemplateService.insert(freightTemplate);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateFreightTemplate")
     @ResponseBody
     public TableResult updateFreightTemplate(FreightTemplate freightTemplate){
         freightTemplate.preUpdate();
        boolean b = freightTemplateService.updateById(freightTemplate);
         return TableResult.Result(b);
     }

     @RequestMapping("/findFreightTemplateOne")
     @ResponseBody
     public TableResult findFreightTemplateOne(FreightTemplate freightTemplate){

        EntityWrapper<FreightTemplate> wrapper = new EntityWrapper<FreightTemplate>();

        if(freightTemplate.getId()!=null){
            wrapper.eq("id",freightTemplate.getId());
        }
        //Todo

        FreightTemplate result = freightTemplateService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findFreightTemplateList")
     @ResponseBody
     public TableResult findFreightTemplateList(FreightTemplate freightTemplate){

        EntityWrapper<FreightTemplate> wrapper = new EntityWrapper<FreightTemplate>();

		if(freightTemplate.getId()!=null){
            wrapper.eq("id",freightTemplate.getId());
        }
        //Todo

        Page<FreightTemplate> page = freightTemplate.getPageInfo();

        page = freightTemplateService.selectPage(page,wrapper);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteFreightTemplate")
     @ResponseBody
     public TableResult deleteFreightTemplate(FreightTemplate freightTemplate){
        freightTemplate.preUpdate();
        boolean b = freightTemplateService.deleteById(freightTemplate.getId());
        return TableResult.Result(b);
     }

}
